﻿// This software is the confidential and proprietary information of NetBay.
// Such confidential information should not be disclosed.
// NetBay copyright(c) 2012

#region

using System;
using System.Collections.Generic;
using System.Linq;
using NetBay.Core.BusinessEntities.Workflow;

#endregion

namespace Rio.Workflow.Runtime
{
    public class KeyedByIdentifierCollection
        : Dictionary<WorkflowAction, Type>
    {
        #region Instance Indexers

        /// <summary>
        /// Gets the <see cref="System.Type" /> with the specified identifier.
        /// </summary>
        /// <value></value>
        [System.Runtime.CompilerServices.IndexerName("Values")]
        public Type this[long identifier]
        {
            get
            {
                var key = GetWorkflowAction(identifier);
                if (key != null)
                    return this[key];
                return null;
            }
        }

        #endregion

        #region Instance Methods

        /// <summary>
        /// Gets the workflow action.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <returns></returns>
        public WorkflowAction GetWorkflowAction(long identifier)
        {
            WorkflowAction key = Keys.SingleOrDefault(p => p.ActionOrConditionId == identifier);
            if (key != null)
                return key;

            return null;
        }

        #endregion
    }
}